package org.tiny.sequence.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tiny.sequence.redis.RedisUtil;

import java.util.Date;

/**
 * @author MMM
 * @desc 订单号生成 唯一数中包含特定的内容，如把当前时间，如20110609132641，作为前缀等
 * @date 2017-03-03 9:57
 **/
@Service
public class OrderNoService {
  private static final String SEQ_KEY = "seq-server-order-no-key";
  @Autowired
  private RedisUtil redisUtil;

  public String next() {
    int seq = redisUtil.incr(SEQ_KEY).intValue();
    String random = RandNumUtil.getRandNum(6);
    String str = String.format("%1$tY%1$tm%1$td%1$tk%1$tM%1$tS%2$s%3$06d", new Date(redisUtil.time()), random, seq);
    return str;
  }
}
